﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Clinica_Frba.Registro_Resultado_Atencion
{
    public partial class Elegiratn : Form
    {
        public Elegiratn()
        {
            InitializeComponent();
        }

        private void Elegiratn_Load(object sender, EventArgs e)
        {
            string comando;
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            comando = "SELECT ID_ATENCION,FECHA,ID_PROF,ID_AFIL,ESTADO FROM DUNDER_MIFFLIN.ATENCION WHERE ESTADO='D'";
            SqlDataAdapter da = new SqlDataAdapter(comando, myConnection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ide;
            string est;
            if (dataGridView1.SelectedRows.Count > 1) { return; }
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                SqlCommand com = new SqlCommand("SELECT ESTADO FROM DUNDER_MIFFLIN.ATENCION WHERE ID_ATENCION=" + Convert.ToInt32(row.Cells[0].Value), myConnection);
                est = Convert.ToString(com.ExecuteScalar());
                if (est == "A") { return; }
                ide = Convert.ToInt32(row.Cells[0].Value);
                Clinica_Frba.Registro_Resultado_Atencion.Atender a = new Clinica_Frba.Registro_Resultado_Atencion.Atender(ide);
                a.Show();                
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string comando;
            SqlConnection myConnection = new SqlConnection(publico.ConnectionString);
            myConnection.Open();
            comando = "SELECT ID_ATENCION,FECHA,ID_PROF,ID_AFIL FROM DUNDER_MIFFLIN.ATENCION WHERE ESTADO='D'";
            SqlDataAdapter da = new SqlDataAdapter(comando, myConnection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
        }
    }
}
